﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using aspProject.Dmain.Domain;
using System.Data.Entity;

namespace aspProject.Dmain.DAL
{
    public class UserRepository : IUserRepository
    {
        private readonly CentricEntities _context;
        private readonly DbSet<User> _users;

        public UserRepository(CentricEntities context)
        {
            this._context = context;
            _users = context.Users;
        }

        public IQueryable<User> FindAll()
        {
            return _users;
        }

        public User FindUser(string username)
        {
            return _users.SingleOrDefault(u => u.Username == username);
        }


        public void SaveChanges()
        {
            _context.SaveChanges();
        }


        public User Login(string username, string password)
        {
            return _users.SingleOrDefault(u => u.Username == username && u.Password == password);
        }
    }
}
